/*--------------------------------------------------------------------------------
 * Adaptive Intelligence - Foundation Framework Class Library
 * Version 2.00
 * 
 * Byte Array Comparer Class
 *      Compares two byte arrays for equivalence.
 *------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------
 * System Imports
 *------------------------------------------------------------------------------*/
using System;
using System.Collections;
using System.Collections.Generic;

 namespace Adaptive.Foundation
 {
     /// <summary>
     /// Compares two byte arrays for equivalence.
     /// </summary>
     /// <typeparam name="T">A byte array specifier.</typeparam>
     public class ByteComparer<T> : IComparer<byte[]>
     {
         /// <summary>
         /// Compares the two arrays.
         /// </summary>
         /// <param name="first">The first byte array to compare.</param>
         /// <param name="second">The second byte array to compare.</param>
         /// <returns></returns>
         public int Compare(byte[] first, byte[] second)
         {
             int returnValue = 0;               //Return value.
             byte[][] data;                     //Data.

             //Set data for comparison.
             data = new byte[2][];
             data[0] = first;
             data[1] = second;

             //Perform comparison.
             if (first.Equals(second))
                 returnValue = 0;
             else
             {
                 //Sort and compare.
                 Array.Sort(data);

                 if (data[0] == first)
                     returnValue = -1;
                 else
                     returnValue = 1;
             }

             return returnValue;
         }
     }
 }
